package com.baizhi.cmfz.service.impl;

import com.baizhi.cmfz.dao.BannerDao;
import com.baizhi.cmfz.entity.Banner;
import com.baizhi.cmfz.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class BannerServiceImpl implements BannerService {
    @Autowired
    private BannerDao bannerDao;

    @Override
    public Map showPageBanner(int page, int limit) {
        int offset=(page-1)*limit;
        List<Banner> list=bannerDao.showPage(offset,limit);
        int count=bannerDao.showCount();
        Map map=new HashMap();
        if(count>0){
            map.put("data",list);
            map.put("count",count);
            map.put("msg","");
            map.put("code",0);
        }
        return map;
    }

    @Override
    public Map insertBanner(Banner banner) {
        int count=bannerDao.insertBanner(banner);
        Map map=new HashMap();
        if(count>0){
            map.put("isInsert","添加成功");
        }else {
            map.put("isInsert","添加失败");
        }
        return map;
    }

    @Override
    public Map deleteBanner(int id) {
        int count=bannerDao.deleteBanner(id);
        Map map=new HashMap();
        if(count>0){
            map.put("isDelete","删除成功");
        }else {
            map.put("isDelete","删除失败");
        }
        return map;
    }

    @Override
    public Banner showOne(int id) {
        return bannerDao.showOne(id);
    }

    @Override
    public Map updateBanner(Banner banner) {
        int count=bannerDao.updateBanner(banner);
        Map map=new HashMap();
        if(count>0){
            map.put("isUpdate","修改成功");
        }else {
            map.put("isUpdate","修改失败");
        }
        return map;
    }

    @Override
    public List<Banner> showFive(int count) {

        return bannerDao.showFive(count);
    }
}
